From 63b5c765a2948e50f72c4058dfa8e71be8f87702 Mon Sep 17 00:00:00 2001 From: "kaf24@firebug.cl.cam.ac.uk" Date: Thu, 19 May 2005 17:36:50 +0000 Subject: [PATCH] bitkeeper revision 1.1466.1.1 (428cceb2sTCzL9rItLSMlnmH9XrnTQ) Ensure correct alignment of CPU0 stack -- it must be aligned on a 2^STACK_ORDER page boundary. This requirement is now also checked at run-time, and a clear fatal error given if it is not satisfied. This bug affected both x86/32 and x86/64. Signed-off-by: Keir Fraser --- xen/arch/x86/boot/x86_32.S | 10 +++++++--- xen/arch/x86/boot/x86_64.S | 12 +++++++----- xen/arch/x86/setup.c | 15 +++++++++++---- 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/xen/arch/x86/boot/x86_32.S b/xen/arch/x86/boot/x86_32.S index 74edbe1ebf..9f7580ab98 100644 --- a/xen/arch/x86/boot/x86_32.S +++ b/xen/arch/x86/boot/x86_32.S @@ -212,9 +212,13 @@ ENTRY(gdt_table) .fill 2*NR_CPUS,8,0 /* space for TSS and LDT per CPU */ .org 0x2000 -ENTRY(idle_pg_table) # Initial page directory is 4kB - .org 0x3000 +/* Maximum STACK_ORDER for x86/32 is 1. We must therefore ensure that the */ +/* CPU0 stack is aligned on an even page boundary! */ ENTRY(cpu0_stack) - .org 0x3000 + STACK_SIZE + + .org 0x2000 + STACK_SIZE +ENTRY(idle_pg_table) + + .org 0x2000 + STACK_SIZE + PAGE_SIZE ENTRY(stext) ENTRY(_stext) diff --git a/xen/arch/x86/boot/x86_64.S b/xen/arch/x86/boot/x86_64.S index 4be1c0684e..a2b2410ae9 100644 --- a/xen/arch/x86/boot/x86_64.S +++ b/xen/arch/x86/boot/x86_64.S @@ -243,8 +243,13 @@ ENTRY(idle_pg_table_4) ENTRY(idle_pg_table_l3) .quad idle_pg_table_l2 - __PAGE_OFFSET + 7 -/* Initial PDE -- level-2 page table. Maps first 64MB physical memory. */ .org 0x4000 +/* Maximum STACK_ORDER for x86/64 is 2. We must therefore ensure that the */ +/* CPU0 stack is aligned on a 4-page boundary. */ +ENTRY(cpu0_stack) + +/* Initial PDE -- level-2 page table. Maps first 64MB physical memory. */ + .org 0x4000 + STACK_SIZE ENTRY(idle_pg_table_l2) .macro identmap from=0, count=32 .if \count-1 @@ -256,10 +261,7 @@ ENTRY(idle_pg_table_l2) .endm identmap /* Too orangey for crows :-) */ - .org 0x5000 -ENTRY(cpu0_stack) - - .org 0x5000 + STACK_SIZE + .org 0x4000 + STACK_SIZE + PAGE_SIZE .code64 ENTRY(stext) ENTRY(_stext) diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c index b30df4de15..ee5c915d06 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -69,6 +69,8 @@ extern void ac_timer_init(void); extern void initialize_keytable(); extern int do_timer_lists_from_pit; +extern unsigned long cpu0_stack[]; + struct cpuinfo_x86 boot_cpu_data = { 0, 0, 0, 0, -1 }; #if defined(CONFIG_X86_64) @@ -381,11 +383,8 @@ static void __init do_initcalls(void) static void __init start_of_day(void) { -#ifdef MEMORY_GUARD /* Unmap the first page of CPU0's stack. */ - extern unsigned long cpu0_stack[]; memguard_guard_stack(cpu0_stack); -#endif open_softirq(NEW_TLBFLUSH_CLOCK_PERIOD_SOFTIRQ, new_tlbflush_clock_period); @@ -469,6 +468,8 @@ static void __init start_of_day(void) #endif } +#define EARLY_FAIL() for ( ; ; ) __asm__ __volatile__ ( "hlt" ) + void __init __start_xen(multiboot_info_t *mbi) { char *cmdline; @@ -495,7 +496,13 @@ void __init __start_xen(multiboot_info_t *mbi) if ( !(mbi->flags & MBI_MODULES) || (mbi->mods_count == 0) ) { printk("FATAL ERROR: Require at least one Multiboot module.\n"); - for ( ; ; ) ; + EARLY_FAIL(); + } + + if ( ((unsigned long)cpu0_stack & (STACK_SIZE-1)) != 0 ) + { + printk("FATAL ERROR: Misaligned CPU0 stack.\n"); + EARLY_FAIL(); } xenheap_phys_end = opt_xenheap_megabytes << 20; -- 2.30.2